﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>添加目录</title>
    <link href="../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../lib/cookie/cookie.js"></script>
</head>
<body>
    <div class="layui-card-body" style="">
        <form class="layui-form" id="catalogueFrom" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">父级目录</label>
                <div class="layui-input-block">
                    <input type="text" name="ParentPath" readonly autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block">
                    <input type="text" name="Name" required lay-verify="required" placeholder="请输入目录名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formsubmit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script>
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
        layui.$().ready(function () {
            var $ = layui.$;
            var itemtemp = getrequest().parentPath;
            if (itemtemp != "") {
                var item = JSON.parse(window.decodeURIComponent(atob(itemtemp)));
                $("input[name='ParentPath']").val(item);
            }
        });
        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(formsubmit)', function (data) {
                layer.msg(JSON.stringify(data.field));
                layer.msg(layui.$('#catalogueFrom').serialize());
                layui.$.ajax({
                    type: "post",
                    url: localStorage.getItem('hosttingaddr') + '/api/Commonconfig/AddCatalogue',
                    headers: {
                        user: getCookie("userinfo"),
                        version: getCookie("version")
                    },
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify(data.field),
                    success: function (data) {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                    },
                    error: function (data) {
                        layer.msg('更新失败!', { icon: 1, time: 1000 });
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                    }
                });
                return false;
            });
        });
    </script>

</body>
</html>